package com.chengjue.transaction.learn.thread.cyclebarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * 描述:
 *
 * @author Kipeng Huang
 * @create 2018-03-03 下午2:10
 */
public class CycleBarrierRunnable implements Runnable {
	private CyclicBarrier cyclicBarrier;

	public CycleBarrierRunnable(CyclicBarrier cyclicBarrier) {
		this.cyclicBarrier = cyclicBarrier;
	}


	@Override
	public void run() {
		System.out.println("当前线程名：" + Thread.currentThread().getName());
		try {
			Thread.sleep(2000);
			cyclicBarrier.await();
			System.out.println("线程" + Thread.currentThread().getName() + "执行完毕");
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			e.printStackTrace();
		}

	}
}
